package cn.bingoogolapple.bgabanner.transformer;

import ohos.agp.components.Component;

/**
 * 作者:王浩 邮件:bingoogolapple@gmail.com
 * 创建时间:15/6/19 上午8:41
 * 描述:
 */
public class RotatePageTransformer extends BGAPageTransformer {
    private float mMaxRotation = 15.0f;

    /**
     * constructor
     */
    public RotatePageTransformer() {
    }

    /**
     * constructor
     *
     * @param maxRotation
     */
    public RotatePageTransformer(float maxRotation) {
        setMaxRotation(maxRotation);
    }

    @Override
    public void handleInvisiblePage(Component view, float position) {
        view.setPivotX(view.getWidth() * 0.5f);
        view.setPivotY(view.getWidth());
        view.setRotation(0);
    }

    @Override
    public void handleLeftPage(Component view, float position) {
        float rotation = mMaxRotation * position;
        view.setPivotX(view.getWidth() * 0.5f);
        view.setPivotY(view.getWidth());
        view.setRotation(rotation);
    }

    @Override
    public void handleRightPage(Component view, float position) {
        handleLeftPage(view, position);
    }

    /**
     * setMaxRotation
     *
     * @param maxRotation
     */
    public void setMaxRotation(float maxRotation) {
        if (maxRotation >= 0.0f && maxRotation <= 40.0f) {
            mMaxRotation = maxRotation;
        }
    }
}